package com.omenkk.juc.ReentrantLock;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.ReentrantLock;

///reentrantLock的可重入性
@Slf4j
public class demo1 {
    static ReentrantLock lock=new ReentrantLock();
    public static void main(String[] args) {
   method1();
    }


    static void method1(){
        new Thread(()->{
            lock.lock();
            try{
                log.debug("method1");
                method2();
            }
            finally {
                lock.unlock();
            }


        }).start();
    }
    static void method2(){
        new Thread(()->{
            lock.lock();
            try{
                log.debug("method2");
                method3();
            }
            finally {
                lock.unlock();
            }


        }).start();
    }

    private static void method3() {
        new Thread(()->{
            lock.lock();
            try{
                log.debug("method3");
            }
            finally {
                lock.unlock();
            }


        }).start();
    }
}
